import {
    http
} from '@/utils/request'

// 首页上次学习课程
export const lastCourse = async (data) => {
    let res = await http.post({
        url: '/essay/last',
        data
    })
    return res
}

// 首页课程列表
export const courseList = async (data) => {
    let res = await http.post({
        url: '/word/wordpackages',
        data
    })
    return res
}

// 首页信息
export const indexInfo = async (data) => {
    let res = await http.post({
        url: '/essay/getcurrinfo',
        data
    })
    return res
}

// 列表信息
export const essayList = async (data) => {
    let res = await http.post({
        url: '/essay/essaylist',
        data
    })
    return res
}

// 范文详情
export const essayDetail = async (data) => {
    let res = await http.post({
        url: '/essay/detail',
        data
    })
    let __res = res
    let __sentence = []
     res.data.sentence.map(item=>{
        __sentence.push(item.replace(/\./g, '. '))
       
    })
    __res.data.sentence = __sentence
    return __res
}

// 检查是否有未结束
export const checkEnd = async (data) => {
    let res = await http.post({
        url: '/essay/checkEnd',
        data
    })
    return res
}

// 打印
export const printText = async (data) => {
    let res = await http.post({
        url: '/essay/printData',
        data
    })
    return res
}


// 添加生词
export const addWord = async (data) => {
    let res = await http.post({
        url: '/read/addword',
        data
    })
    return res
}

// 保存大步骤
export const saveStep = async (data) => {
    let res = await http.post({
        url: '/essay/saveStep',
        data
    })
    return res
}

// 随机数组
export const randomArr = async (data, key = '') => {
    let res = await http.post({
        url: `/useronline/checkonline${key}`,
        data
    })
    return res
}

// 透传-用于远控传递数据
export const penetrate = async (data, key = '') => {
    let res = await http.post({
        url: `/useronline/checkonline${key}`,
        data
    })
    return res
}

// 报告列表
export const reportList = async (data) => {
    let res = await http.post({
        url: '/essay/reportList',
        data
    })
    return res
}

// 查词
export const searchWord = async (data) => {
    let str = ''
    if (data.word.indexOf('@') !== -1) {
        str = data.word.replace(/<[^>]*>/g, ''); // eslint-disable-line
    } else {
        str = data.word.replace(/<[^>]*>/g, '').match(/(([a-z]+[\-\']+[a-z]+)|([a-z]+))/ig)[0] || ""; // eslint-disable-line
    }
    const fmdata = {
        word: str
    }
    const res = await http.post({
        url: '/read/searchword'+ '?' + str,
        data: fmdata
    })
    return res
}

// 上传音频文件
export const uploadAudio = async (data) => {
    console.log(data)
    let res = await http.post({
        url: '/common/uploadonline',
        data,
        config: {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }
    })
    return res
}

// 提交录音和得分
export const subVoice = async (data) => {
    let res = await http.post({
        url: '/essay/subVoice',
        data
    })
    return res
}

// 作业二维码
export const createQrcode = async (data) => {
    let res = await http.post({
        url: '/essay/createqrcodebyid',
        data
    })
    return res
}

// 获取作文图片
export const getChropath = async (data) => {
    let res = await http.post({
        url: '/essay/synchropath',
        data
    })
    return res
}

// 范文结束学习
export const subEssay = async (data) => {
    let res = await http.post({
        url: '/essay/subEssay',
        data
    })
    return res
}

// 报告详情
export const reportDetail = async (data) => {
    let res = await http.post({
        url: '/essay/reportDetail',
        data
    })
    return res
}
